import { isDev } from "../utils/env";

const testToken =
  "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJxbWcuY24iLCJhdWQiOiJxbWcuY24iLCJpYXQiOjE3MzY1NjU2MDEsIm5iZiI6MTczNjU2NTY2MSwiZXhwIjoxNzM2NjM3NjAxLCJleHRlbmQiOnsiaWQiOjksIm5pY2tuYW1lIjoiXHU2YjIyXHU1MTUyIn19.LeCO5ph9mXm9loB1IvGvgzYvuGHIaWlqekSFBItdP5k";

const PREFIX = "__MGDJH5__";

const APPKEY = {
  token: PREFIX + "token",
  refreshToken: PREFIX + "refreshToken",
};

/**
 * 缓存用户token
 */
export const useSetTokenStorage = (data) => {
  let token = data;
  if (isDev) {
    // token = testToken;
  }
  uni.setStorageSync(APPKEY.token, token);
};

/**
 * 获取用户token
 */
export const useGetTokenStorage = () => {
  return uni.getStorageSync(APPKEY.token);
};

/**
 * 缓存刷新refresh_token
 */
export const useSetRefreshTokenStorage = (data) => {
  uni.setStorageSync(APPKEY.refreshToken, data);
};

/**
 * 获取refresh_token
 */
export const useGetRefreshTokenStorage = () => {
  return uni.getStorageSync(APPKEY.refreshToken);
};
